﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace CheckedItems
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private StringBuilder text = new StringBuilder();
        bool[] checkedCB = new bool[4];
        public MainWindow()
        {
            InitializeComponent();
            text.Append("Checked boxes: ");
        }

        private void CB_Checked(object sender, RoutedEventArgs e)
        {
            int num = Convert.ToInt32(((CheckBox)sender).Content.ToString());
            checkedCB[num - 1] = true;
            LoadLbl();
        }

        private void LoadLbl()
        {
            text.Clear();
            text.Append("Checked boxes: ");
            for (int i = 0; i < 4; i++)
            {
                if (checkedCB[i])
                {
                    text.Append(string.Format("{0} ", i + 1));
                } 
            }
            this.checkedLbl.Content = text.ToString();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            this.checkedLbl.Content = text.ToString();
        }

        private void CB_Unchecked(object sender, RoutedEventArgs e)
        {
            int num = Convert.ToInt32(((CheckBox)sender).Content.ToString());
            checkedCB[num - 1] = false;
            LoadLbl();     
        }
    }
}